home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 23.2 KB | 776 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWStrmRW.h
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWSTRMRW_H
- #define FWSTRMRW_H
-
- #ifndef FWODEXCE_H
- #include "FWODExce.h"
- #endif
-
- #ifndef SLSTRMRW_H
- #include "SLStrmRW.h"
- #endif
-
- //========================================================================================
- // Constants
- //========================================================================================
-
- // These values influence how numbers are written/read to/from streams. The default is
- // to use the native format.
-
- const int FW_kStream_NativeEndian = 0;
- const int FW_kStream_LittleEndian = 1;
- const int FW_kStream_BigEndian = 2;
-
-
- //========================================================================================
- // CLASS FW_CReadableStream
- //========================================================================================
-
- class FW_CReadableStream : public FW_SReadableStream
- {
- public:
-
- FW_DECLARE_AUTO(FW_CReadableStream)
-
- FW_CReadableStream(FW_OSink* sink,
- FW_OObjectRegistry* objectRegistry = 0,
- int numberFormat = FW_kStream_NativeEndian);
- FW_CReadableStream(FW_HReadableStream hStream);
- ~FW_CReadableStream();
-
- operator FW_HReadableStream();
- FW_OSink* GetSink() const;
- FW_OObjectRegistry* GetRegistry() const;
-
- // ----- void
-
- void Read(void* buffer, long count);
- // Read 'count' bytes into buffer.
-
- // ----- char
-
- void Read(char* buffer, long count);
- // Read 'count' chars into buffer.
-
- char GetChar();
- // Get char.
-
- // ----- signed char
-
- void Read(signed char* buffer, long count);
- // Read 'count' signed chars into buffer.
-
- signed char GetSignedChar();
- // Get signed char.
-
- // ----- unsigned char
-
- void Read(unsigned char* buffer, long count);
- // Read 'count' unsigned chars into buffer.
-
- unsigned char GetUnsignedChar();
- // Get unsigned char.
-
- // ----- short
-
- void Read(short* buffer, long count);
- // Read 'count' shorts into buffer.
-
- short GetShort();
- // Get short.
-
- // ----- unsigned short
-
- void Read(unsigned short* buffer, long count);
- // Read 'count' unsigned shorts into buffer.
-
- unsigned short GetUnsignedShort();
- // Get unsigned short.
-
- // ----- long
-
- void Read(long* buffer, long count);
- // Read 'count' longs into buffer.
-
- long GetLong();
- // Get long.
-
- // ----- unsigned long
-
- void Read(unsigned long* buffer, long count);
- // Read 'count' unsigned longs into buffer.
-
- unsigned long GetUnsignedLong();
- // Get unsigned long.
-
- // ----- int
-
- void Read(int* buffer, long count);
- // Read 'count' ints into buffer.
-
- int GetInt();
- // Get int.
-
- // ----- unsigned int
-
- void Read(unsigned int* buffer, long count);
- // Read 'count' unsigned ints into buffer.
-
- unsigned int GetUnsignedInt();
- // Get unsigned int.
-
- // ----- float
-
- void Read(float* buffer, long count);
- // Read 'count' floats into buffer.
-
- float GetFloat();
- // Get float.
-
- // ----- double
-
- void Read(double* buffer, long count);
- // Read 'count' doubles into buffer.
-
- double GetDouble();
- // Get double.
-
- private:
- FW_CReadableStream(const FW_CReadableStream& theStream);
- FW_CReadableStream& operator=(const FW_CReadableStream& theStream);
- // Can't copy instances of this class.
- FW_CReadableStream(const FW_SReadableStream& readableStream);
- };
-
- //----------------------------------------------------------------------------------------
- // inline operator >>
- //----------------------------------------------------------------------------------------
-
- inline FW_CReadableStream& operator>>(FW_CReadableStream& s, char& aChar)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadChars(&s, &aChar, 1));
- return s;
- }
-
- inline FW_CReadableStream& operator>>(FW_CReadableStream& s, char* nullTerminatedString)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadNullTerminatedString(&s, nullTerminatedString));
- return s;
- }
-
- inline FW_CReadableStream& operator>>(FW_CReadableStream& s, signed char& aChar)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadChars(&s, (char*) &aChar, 1));
- return s;
- }
-
- inline FW_CReadableStream& operator>>(FW_CReadableStream& s, unsigned char& aChar)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadChars(&s, (char*) &aChar, 1));
- return s;
- }
-
- inline FW_CReadableStream& operator>>(FW_CReadableStream& s, short& aShort)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadShorts(&s, &aShort, 1));
- return s;
- }
-
- inline FW_CReadableStream& operator>>(FW_CReadableStream& s, unsigned short& unsignedShort)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadShorts(&s, (short*) &unsignedShort, 1));
- return s;
- }
-
- inline FW_CReadableStream& operator>>(FW_CReadableStream& s, long& aLong)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadLongs(&s, &aLong, 1));
- return s;
- }
-
- inline FW_CReadableStream& operator>>(FW_CReadableStream& s, unsigned long& unsignedLong)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadLongs(&s, (long*) &unsignedLong, 1));
- return s;
- }
-
- inline FW_CReadableStream& operator>>(FW_CReadableStream& s, int& aInt)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadInts(&s, &aInt, 1));
- return s;
- }
-
- inline FW_CReadableStream& operator>>(FW_CReadableStream& s, unsigned int& unsignedInt)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadInts(&s, (int*) &unsignedInt, 1));
- return s;
- }
-
- inline FW_CReadableStream& operator>>(FW_CReadableStream& s, float& aFloat)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadFloats(&s, &aFloat, 1));
- return s;
- }
-
- inline FW_CReadableStream& operator>>(FW_CReadableStream& s, double& aDouble)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadDoubles(&s, &aDouble, 1));
- return s;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::GetSink
- //----------------------------------------------------------------------------------------
-
- inline FW_OSink* FW_CReadableStream::GetSink() const
- {
- return fSink;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::GetRegistry
- //----------------------------------------------------------------------------------------
-
- inline FW_OObjectRegistry* FW_CReadableStream::GetRegistry() const
- {
- return fObjectRegistry;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::operator FW_HReadableStream
- //----------------------------------------------------------------------------------------
-
- inline FW_CReadableStream::operator FW_HReadableStream()
- {
- return this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::Read
- //----------------------------------------------------------------------------------------
-
- inline void FW_CReadableStream::Read(void* buffer, long count)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadBytes(this, buffer, count));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::Read
- //----------------------------------------------------------------------------------------
-
- inline void FW_CReadableStream::Read(char* buffer, long count)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadChars(this, buffer, count));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::GetChar
- //----------------------------------------------------------------------------------------
-
- inline char FW_CReadableStream::GetChar()
- {
- char x;
- *this >> x;
- return x;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::Read
- //----------------------------------------------------------------------------------------
-
- inline void FW_CReadableStream::Read(signed char* buffer, long count)
- {
- Read((char*) buffer, count);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::GetSignedChar
- //----------------------------------------------------------------------------------------
-
- inline signed char FW_CReadableStream::GetSignedChar()
- {
- return (signed char)GetChar();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::Read
- //----------------------------------------------------------------------------------------
-
- inline void FW_CReadableStream::Read(unsigned char* buffer, long count)
- {
- Read((char*) buffer, count);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::GetUnsignedChar
- //----------------------------------------------------------------------------------------
-
- inline unsigned char FW_CReadableStream::GetUnsignedChar()
- {
- return (unsigned char)GetChar();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::Read
- //----------------------------------------------------------------------------------------
-
- inline void FW_CReadableStream::Read(short* buffer, long count)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadShorts(this, buffer, count));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::GetShort
- //----------------------------------------------------------------------------------------
-
- inline short FW_CReadableStream::GetShort()
- {
- short x;
- *this >> x;
- return x;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::Read
- //----------------------------------------------------------------------------------------
-
- inline void FW_CReadableStream::Read(unsigned short* buffer, long count)
- {
- Read((short*) buffer, count);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::GetUnsignedShort
- //----------------------------------------------------------------------------------------
-
- inline unsigned short FW_CReadableStream::GetUnsignedShort()
- {
- return (unsigned short) GetShort();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::Read
- //----------------------------------------------------------------------------------------
-
- inline void FW_CReadableStream::Read(long* buffer, long count)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadLongs(this, buffer, count));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::GetLong
- //----------------------------------------------------------------------------------------
-
- inline long FW_CReadableStream::GetLong()
- {
- long x;
- *this >> x;
- return x;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::Read
- //----------------------------------------------------------------------------------------
-
- inline void FW_CReadableStream::Read(unsigned long* buffer,
- long count)
- {
- Read((long*) buffer, count);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::GetUnsignedLong
- //----------------------------------------------------------------------------------------
-
- inline unsigned long FW_CReadableStream::GetUnsignedLong()
- {
- return (unsigned long) GetLong();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::Read
- //----------------------------------------------------------------------------------------
-
- inline void FW_CReadableStream::Read(int* buffer, long count)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadInts(this, buffer, count));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::GetInt
- //----------------------------------------------------------------------------------------
-
- inline int FW_CReadableStream::GetInt()
- {
- int x;
- *this >> x;
- return x;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::Read
- //----------------------------------------------------------------------------------------
-
- inline void FW_CReadableStream::Read(unsigned int* buffer, long count)
- {
- Read((int*) buffer, count);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::GetUnsignedInt
- //----------------------------------------------------------------------------------------
-
- inline unsigned int FW_CReadableStream::GetUnsignedInt()
- {
- return (unsigned int)GetInt();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::Read
- //----------------------------------------------------------------------------------------
-
- inline void FW_CReadableStream::Read(float* buffer, long count)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadFloats(this, buffer, count));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::GetFloat
- //----------------------------------------------------------------------------------------
-
- inline float FW_CReadableStream::GetFloat()
- {
- float x;
- *this >> x;
- return x;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::Read
- //----------------------------------------------------------------------------------------
-
- inline void FW_CReadableStream::Read(double* buffer, long count)
- {
- ::FW_FailOnError(FW_PrivReadableStream_ReadDoubles(this, buffer, count));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::GetDouble
- //----------------------------------------------------------------------------------------
-
- inline double FW_CReadableStream::GetDouble()
- {
- double x;
- *this >> x;
- return x;
- }
-
- //========================================================================================
- // CLASS FW_CWritableStream
- //========================================================================================
-
- class FW_CWritableStream : public FW_SWritableStream
- {
- public:
-
- FW_DECLARE_AUTO(FW_CWritableStream)
-
- FW_CWritableStream(FW_OSink* sink,
- FW_OObjectRegistry* objectRegistry = 0,
- int numberFormat = FW_kStream_NativeEndian);
- FW_CWritableStream(FW_HWritableStream hStream);
- ~FW_CWritableStream();
-
- operator FW_HWritableStream();
- FW_OSink* GetSink() const;
- FW_OObjectRegistry* GetRegistry() const;
-
- // ----- void
-
- void Write(const void* buffer, long count);
- // Write 'count' bytes from buffer.
-
- // ----- char
-
- void Write(const char* buffer, long count);
- // Write 'count' chars from buffer.
-
- // ----- signed char
-
- void Write(const signed char* buffer, long count);
- // Write 'count' signed chars from buffer.
-
- // ----- unsigned char
-
- void Write(const unsigned char* buffer, long count);
- // Write 'count' unsigned chars from buffer.
-
- // ----- short
-
- void Write(const short* buffer, long count);
- // Write 'count' shorts from buffer.
-
- // ----- unsigned short
-
- void Write(const unsigned short* buffer, long count);
- // Write 'count' unsigned shorts from buffer.
-
- // ----- long
-
- void Write(const long* buffer, long count);
- // Write 'count' longs from buffer.
-
- // ----- unsigned long
-
- void Write(const unsigned long* buffer, long count);
- // Write 'count' unsigned longs from buffer.
-
- // ----- int
-
- void Write(const int* buffer, long count);
- // Write 'count' ints from buffer.
-
- // ----- unsigned int
-
- void Write(const unsigned int* buffer, long count);
- // Write 'count' unsigned ints from buffer.
-
- // ----- float
-
- void Write(const float* buffer, long count);
- // Write 'count' floats from buffer.
-
- // ----- double
-
- void Write(const double* buffer, long count);
- // Write 'count' doubles from buffer.
-
- private:
- FW_CWritableStream(const FW_CWritableStream& theStream);
- FW_CWritableStream& operator=(const FW_CWritableStream& theStream);
- // Can't copy instances of this class.
- FW_CWritableStream(const FW_SWritableStream& writableStream);
- };
-
-
- //----------------------------------------------------------------------------------------
- // inline operator <<
- //----------------------------------------------------------------------------------------
-
- inline FW_CWritableStream& operator<<(FW_CWritableStream& s, char aChar)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteChars(&s, &aChar, 1));
- return s;
- }
-
- inline FW_CWritableStream& operator<<(FW_CWritableStream& s, char *nullTerminatedString)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteNullTerminatedString(&s, nullTerminatedString));
- return s;
- }
-
- inline FW_CWritableStream& operator<<(FW_CWritableStream& s, signed char aChar)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteChars(&s, (const char*) &aChar, 1));
- return s;
- }
-
- inline FW_CWritableStream& operator<<(FW_CWritableStream& s, unsigned char aChar)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteChars(&s, (const char*) &aChar, 1));
- return s;
- }
-
- inline FW_CWritableStream& operator<<(FW_CWritableStream& s, short aShort)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteShorts(&s, &aShort, 1));
- return s;
- }
-
- inline FW_CWritableStream& operator<<(FW_CWritableStream& s, unsigned short unsignedShort)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteShorts(&s, (const short*) &unsignedShort, 1));
- return s;
- }
-
- inline FW_CWritableStream& operator<<(FW_CWritableStream& s, long aLong)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteLongs(&s, &aLong, 1));
- return s;
- }
-
- inline FW_CWritableStream& operator<<(FW_CWritableStream& s, unsigned long unsignedLong)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteLongs(&s, (const long*) &unsignedLong, 1));
- return s;
- }
-
- inline FW_CWritableStream& operator<<(FW_CWritableStream& s, int aInt)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteInts(&s, &aInt, 1));
- return s;
- }
-
- inline FW_CWritableStream& operator<<(FW_CWritableStream& s, unsigned int unsignedInt)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteInts(&s, (const int*) &unsignedInt, 1));
- return s;
- }
-
- inline FW_CWritableStream& operator<<(FW_CWritableStream& s, float aFloat)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteFloats(&s, &aFloat, 1));
- return s;
- }
-
- inline FW_CWritableStream& operator<<(FW_CWritableStream& s, double aDouble)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteDoubles(&s, &aDouble, 1));
- return s;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::GetSink
- //----------------------------------------------------------------------------------------
-
- inline FW_OSink* FW_CWritableStream::GetSink() const
- {
- return fSink;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::GetRegistry
- //----------------------------------------------------------------------------------------
-
- inline FW_OObjectRegistry* FW_CWritableStream::GetRegistry() const
- {
- return fObjectRegistry;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::operator FW_HWritableStream
- //----------------------------------------------------------------------------------------
-
- inline FW_CWritableStream::operator FW_HWritableStream()
- {
- return this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::Write
- //----------------------------------------------------------------------------------------
-
- inline void FW_CWritableStream::Write(const void* buffer, long count)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteBytes(this, buffer, count));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::Write
- //----------------------------------------------------------------------------------------
-
- inline void FW_CWritableStream::Write(const char* buffer, long count)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteChars(this, buffer, count));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::Write
- //----------------------------------------------------------------------------------------
-
- inline void FW_CWritableStream::Write(const signed char* buffer, long count)
- {
- Write((const char*) buffer, count);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::Write
- //----------------------------------------------------------------------------------------
-
- inline void FW_CWritableStream::Write(const unsigned char* buffer, long count)
- {
- Write((const char*) buffer, count);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::Write
- //----------------------------------------------------------------------------------------
-
- inline void FW_CWritableStream::Write(const short* buffer, long count)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteShorts(this, buffer, count));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::Write
- //----------------------------------------------------------------------------------------
-
- inline void FW_CWritableStream::Write(const unsigned short* buffer, long count)
- {
- Write((const short*) buffer, count);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::Write
- //----------------------------------------------------------------------------------------
-
- inline void FW_CWritableStream::Write(const long* buffer, long count)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteLongs(this, buffer, count));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::Write
- //----------------------------------------------------------------------------------------
-
- inline void FW_CWritableStream::Write(const unsigned long* buffer, long count)
- {
- Write((const long*) buffer, count);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::Write
- //----------------------------------------------------------------------------------------
-
- inline void FW_CWritableStream::Write(const int* buffer, long count)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteInts(this, buffer, count));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::Write
- //----------------------------------------------------------------------------------------
-
- inline void FW_CWritableStream::Write(const unsigned int* buffer, long count)
- {
- Write((const int*) buffer, count);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::Write
- //----------------------------------------------------------------------------------------
-
- inline void FW_CWritableStream::Write(const float* buffer, long count)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteFloats(this, buffer, count));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::Write
- //----------------------------------------------------------------------------------------
-
- inline void FW_CWritableStream::Write(const double* buffer, long count)
- {
- ::FW_FailOnError(FW_PrivWritableStream_WriteDoubles(this, buffer, count));
- }
-
- #endif
-